package NC41_最长无重复子数组;

import java.util.*;


public class Solution {
    /**
     *
     * @param arr int整型一维数组 the array
     * @return int整型
     */
    public int maxLength (int[] arr) {
        // write code here
        int res = 0;
        int left = 0, right = 0;
        Set<Integer> set = new TreeSet<>();
        while (right < arr.length){
            while (set.contains(arr[right])){
                set.remove(arr[left++]);
            }
            set.add(arr[right++]);
            res = Math.max(res, right - left);
        }
        return res;
    }
}